package com.example.framework509.common.callback;

import javax.servlet.http.HttpServletRequest;

public class AutoProcessControllerPart {

    private AutoProcessInterface getPart;

    private AutoProcessInterface addPart;

    private AutoProcessInterface putPart;

    private AutoProcessInterface delPart;

    public AutoProcessControllerPart() {

    }

    public void setGetPartCallback(AutoProcessInterface autoProcess){
        this.getPart = autoProcess;
    }

    public void setAddPartCallback(AutoProcessInterface autoProcess){
        this.addPart = autoProcess;
    }

    public void setPutPartCallback(AutoProcessInterface autoProcess){
        this.putPart = autoProcess;
    }

    public void setDelPartCallback(AutoProcessInterface autoProcess){
        this.delPart = autoProcess;
    }

    public Object process(HttpServletRequest httpServletRequest) throws Throwable{
        String requestType = httpServletRequest.getMethod();
        if (requestType.equals("GET")&&getPart!=null)
            return this.getPart.onCallBack();
        else if (requestType.equals("POST")&&addPart!=null)
            return this.addPart.onCallBack();
        else if (requestType.equals("PUT")&&putPart!=null)
            return this.putPart.onCallBack();
        else if (requestType.equals("DELETE")&&delPart!=null)
            return this.delPart.onCallBack();
        else
            return null;
    }

}
